home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Devices and Hardware / SCSI / SCSI Find Devices / SCSIFindDevicesMain.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  2.5 KB  |  91 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        SCSIFindDevicesMain.c
  3.  
  4.     Contains:    This sample shows how to locate all attached SCSI devices.
  5.  
  6.     Written by: Martin Minow.    
  7.  
  8.     Copyright:    Copyright © 1992-1999 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.                 7/14/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  20.                 
  21.  
  22. */
  23. #include <Folders.h>
  24. #include <Errors.h>
  25. #include <stdio.h>
  26. #ifdef THINK_C
  27. #include <console.h>
  28. #endif
  29. #include "SCSIFindDevices.h"
  30.  
  31. SCSIFindDevicesRec            gSCSIFindDevicesRec;
  32.  
  33. void
  34. main(
  35. #ifdef THINK_C
  36.         int                    argc,
  37.         char                **argv
  38. #endif
  39.     )
  40. {
  41.         OSErr                status;
  42.         int                    devicesFound;
  43.         
  44. #ifdef THINK_C
  45.         argc = ccommand(&argv);
  46. #endif
  47.         /*
  48.          * Initialize the Find "global" area. If deviceID.bus is 0xFF, the
  49.          * find subroutine will initialize and return the first device.
  50.          * Set the maxLUN field to zero to prevent multiple LUN recognition
  51.          * or set it to seven to enable all LUNs.
  52.          */
  53.         gSCSIFindDevicesRec.deviceID.bus = 0xFF;
  54.         gSCSIFindDevicesRec.maxLUN = 7;
  55.         devicesFound = 0;
  56.         while ((status = SCSIFindNextDevice(&gSCSIFindDevicesRec)) == noErr) {
  57.             ++devicesFound;
  58.             if (gSCSIFindDevicesRec.isAsyncSCSIPresent) {
  59.                 printf("%d.%d.%d \"%.8s\" \"%.16s\"\n",
  60.                     (int) gSCSIFindDevicesRec.deviceID.bus,
  61.                     (int) gSCSIFindDevicesRec.deviceID.targetID,
  62.                     (int) gSCSIFindDevicesRec.deviceID.LUN,
  63.                     gSCSIFindDevicesRec.inquiry.vendor,
  64.                     gSCSIFindDevicesRec.inquiry.product
  65.                 );
  66.             }
  67.             else {
  68.                 printf("%d.%d \"%.8s\" \"%.16s\"\n",
  69.                     (int) gSCSIFindDevicesRec.deviceID.targetID,
  70.                     (int) gSCSIFindDevicesRec.deviceID.LUN,
  71.                     gSCSIFindDevicesRec.inquiry.vendor,
  72.                     gSCSIFindDevicesRec.inquiry.product
  73.                 );
  74.             }
  75.         }
  76.         if (status == eofErr)
  77.             printf("Normal completion, %d devices found\n", devicesFound);
  78.         else {
  79.             printf("Failure: system error %d after finding %d devices\n",
  80.                 (int) status,
  81.                 devicesFound
  82.             );
  83.         }
  84.         if (gSCSIFindDevicesRec.isAsyncSCSIPresent)
  85.             printf("Using asynchronous SCSI Manager\n");
  86.         else {
  87.             printf("Using original SCSI Manager only\n");
  88.         }
  89. }
  90.  
  91.